package com.base.lib.utils.eventbus;

import androidx.annotation.Nullable;

import com.base.lib.base.BaseJson;

import org.greenrobot.eventbus.EventBus;

/**
 * 发起EventBus信息
 *
 * @author harisucici
 * @date 2017/6/13
 */

public class EventBusHelper {

    public static final int RESPONSE_NULL = -11;    //返回的BaseJson为空
    public static final int LOGIN_SUCCESS = 66;     //登录成功
    public static final int LOGIN_STATUS_ERROR = -99;
    public static final int UPDATA_MY_INFO_SUCCESS = 71;
    public static final int NO_MORE_DATA = 2004;    //沒有更多數據
    public static final int LOCATION_SUCCESS = 661;    //定位成功
    public static final int HIDE_PERSONAL_FRAGMENT = 401;
    public static final int HIDE_PERSON_FRAGMENT = 402;
    public static final int SAVE_PERSON_FRAGMENT = 407;
    public static final int SHOW_EDIT_FRAGMENT = 403;
    public static final int HIDE_EDIT_FRAGMENT = 404;
    public static final int SAVE_EDIT_FRAGMENT = 406;
    public static final int GOTO_COLLECTION = 405;
    public static final int PERSONNEW_INDEX_NORMAL = 998; //量体控件跳转定位
    public static final int DATA_PERSON_CHANGE_IMG = 997; //刷新图片跳转
    public static final int DATA_PERSON_CHANGE_SIZE = 999; //刷新图片跳转
    public static final int SETTING_CLOTHES_ID = 996; //点击跳转号型
    public static final int REFRESH_UI = 995; //点击跳转号型
    /**
     * janus收到event内容为unpublished的信息
     */
    public static final int JANUS_RECEIVE_UNPUBLISHED = 70;
    /**
     * 视频已从服务器终止
     */
    public static final int JANUS_RECEIVE_HANG_UP = 664;
    private static final String TAG = "EventBusHelper";

    public static void sendEventBusMsg(int code, String msg) {
        EventBus.getDefault().post(new EventBusMessage(code, msg));
    }

    public static void sendEventBusMsg(int code, String msg, long time, int type) {
        EventBus.getDefault().post(new EventBusMessage(code, msg, time, type));
    }

    public static void sendEventBusMsg(int code) {
        EventBus.getDefault().post(new EventBusMessage(code));
    }

    public static void sendEventBusMsg(String msg) {
        EventBus.getDefault().post(new EventBusMessage(msg));
    }

    public static void handleBaseJson(@Nullable BaseJson baseJson) {
        if (baseJson != null) {
            if (baseJson.getCode() == 0 || baseJson.getCode() == 201) {

            } else {
                sendEventBusMsg(baseJson.getCode(), baseJson.getMsg());
            }
        } else {
            sendEventBusMsg(RESPONSE_NULL, "");
        }
    }
}
